import { createRouter, createWebHistory } from 'vue-router'

//导入组件
import LoginVue from '@/views/Login.vue'
import LayoutVue from '@/views/Layout.vue'
import BooksVue from '@/views/library/Books.vue'
import ClassifyVue from '@/views/library/Classify.vue'
import BorrowVue from '@/views/library/Borrow.vue'
import ReaderVue from '@/views/library/Reader.vue'
import UserInfoVue from '@/views/user/UserInfo.vue'
import UserResetPasswordVue from '@/views/user/UserResetPassword.vue'

//定义路由关系
const routes = [
    { path: '/login', component: LoginVue,meta: {
        title: '图书管理系统' // 设置标题为'登录'
      }},
    {
        path: '/', component: LayoutVue, redirect: '/library/books', children: [
            { path: '/library/books', component: BooksVue ,
            meta: {
                title: '图书列表' // 设置标题为'首页'
              }},
            { path: '/library/borrow', component: BorrowVue ,
            meta: {
                title: '借阅管理' 
              }},
            { path: '/library/reader', component: ReaderVue ,
            meta: {
                title: '借阅人列表' 
              }},
            { path: '/library/classify', component: ClassifyVue ,
            meta: {
                title: '分类管理' 
              }},
            { path: '/user/userInfo', component: UserInfoVue ,
            meta: {
                title: '基本信息修改' 
              }},
            { path: '/user/userResetPassword', component: UserResetPasswordVue ,
            meta: {
                title: '密码修改' 
              }}
        ]
    },
    
]

//创建路由器
const router = createRouter({
    history: createWebHistory(),
    routes: routes

});

router.beforeEach((to, from, next) => {
    if (to.meta.title) {
        document.title = to.meta.title;
    }
    next();
});

//导出路由
export default router


